package com.cloudfun.campusshare.entity;

import com.cloudfun.campusshare.common.constant.miniprogram.WeChatReturnCode;
import com.cloudfun.campusshare.common.constant.miniprogram.WeChatTradeState;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.time.LocalDateTime;

/**
 * 微信支付
 * Created by Huqin on 2020/4/21
 */
@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "wechat_payment")
public class WeChatPaymentEntity extends BaseEntity {

    @Id
    @GenericGenerator(name = "id_uuid", strategy = "uuid")
    @GeneratedValue(generator = "id_uuid")
    @Column(unique = true, columnDefinition = ("varchar(40) not null comment '主键uuid'"))
    private String id;

    @Column(columnDefinition = ("varchar(32) not null comment '微信应用id'"))
    private String appId;

    @Column(columnDefinition = ("varchar(32) not null comment '商户号'"))
    private String merchantId;

    @Enumerated(EnumType.STRING)
    @Column(columnDefinition = ("varchar(32) not null comment '业务结果'"))
    private WeChatReturnCode resultCode;

    @Column(columnDefinition = ("varchar(32) default null comment '错误代码'"))
    private String errCode;

    @Column(columnDefinition = ("varchar(128) default null comment '错误代码描述'"))
    private String errCodeDes;

    @Column(columnDefinition = ("varchar(128) not null comment '用户标识'"))
    private String openId;

    @Column(columnDefinition = ("varchar(16) default null comment '交易类型'"))
    private String tradeType;

    @Column(columnDefinition = ("varchar(32) not null comment '付款银行'"))
    private String bankType;

    @Column(columnDefinition = ("int(5) not null comment '订单金额'"))
    private Integer totalFee;

    @Column(columnDefinition = ("int(5) not null comment '现金支付金额'"))
    private Integer cashFee;

    @Enumerated(EnumType.STRING)
    @Column(columnDefinition = ("varchar(32) default null comment '交易状态'"))
    private WeChatTradeState tradeState;

    @Column(columnDefinition = ("varchar(32) not null comment '微信支付订单号'"))
    private String transactionId;

    @Column(columnDefinition = ("varchar(32) not null comment '商户订单号'"))
    private String outTradeNo;

    @Column(columnDefinition = ("varchar(128) default null comment '商家数据包'"))
    private String attach;

    @Column(columnDefinition = ("timestamp(6) not null comment '支付完成时间'"))
    private LocalDateTime timeEnd;

    @Column(columnDefinition = ("varchar(32) default null comment '委托代扣协议id'"))
    private String contractId;

    @Column(columnDefinition = ("varchar(40) not null comment '订单id'"))
    private String orderId;

    @Column(columnDefinition = ("varchar(40) not null comment '用户id'"))
    private String customerId;

}
